package com.wswy.wzcx.ui.other

import android.app.Activity
import com.che.libcommon.ui.BaseFragment
import com.che.libcommon.ui.ICloseWatcher
import com.che.libcommon.utils.RxBus
import io.reactivex.disposables.CompositeDisposable
import kotlin.reflect.KFunction

/**
 * Created by wangduheng26 on 2018/4/12.
 * wangduheng26@gmail.com
 * note: when fragment or activity call destroy must call this onDestroy()
 */
class CloseDelegate(view: ICloseWatcher,vararg codes: Int) {


    val disposables = CompositeDisposable()

    init {


        codes.forEach {
            disposables.add(RxBus.getDefault()
                    .toObservableWithCode(it, String::class.java).subscribe {
                        view.finishView()
                    })
        }


    }

    fun onDestroy() {
        disposables.clear()
    }

}

